home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 June / CHIP Haziran 2001.iso / prog / haziran / 19 / setup.exe / data.z / windrvr.h < prev    next >
C/C++ Source or Header  |  2001-04-11  |  41KB  |  1,206 lines

  1. /* 
  2.  * W i n D r i v e r    v 5 . 0 0
  3.  * ==============================
  4.  *
  5.  * Header file for Windows 95/98/ME/NT/NTE/NT2000/CE/Linux/Solaris/VxWorks.
  6.  * FOR DETAILS ON THE WinDriver FUNCTIONS, PLEASE SEE THE WinDriver MANUAL
  7.  * OR INCLUDED HELP FILES.
  8.  *
  9.  * This file may not be distributed -- it may only be used for development
  10.  * or evaluation purposes. (see \WinDriver\docs\license.txt for details).
  11.  *
  12.  * Web site: http://www.jungo.com
  13.  * Email:    support@jungo.com
  14.  *
  15.  * (C) Jungo 2001
  16.  */
  17. #ifndef _WINDRVR_H_
  18. #define _WINDRVR_H_
  19.  
  20. #if defined(__cplusplus)
  21.     extern "C" {
  22. #endif
  23.  
  24. // these lines break standard VxWorks builds. remove the -asni flag from the
  25. // compiler flags (from the makefile or the Tornado IDE) to compile WinDriver
  26. // related source code.
  27. #define WD_VER      500
  28.  
  29.  
  30. #if defined(VXWORKS)
  31.     #define WD_PROD_NAME "DriverBuilder"
  32. #else
  33.     #define WD_PROD_NAME "WinDriver"
  34. #endif
  35.  
  36. #if defined(VXWORKS)
  37.     #if defined(MBX860)     
  38.         #define WD_CPU_SPEC " PPC860"
  39.     #elif defined(MCP750)
  40.         #define WD_CPU_SPEC " PPC750"
  41.     #elif defined(x86)
  42.         #define WD_CPU_SPEC " X86"
  43.     #else      
  44.         #define WD_CPU_SPEC ""
  45.     #endif
  46. #else
  47.     #if defined(SPARC)     
  48.         #define WD_CPU_SPEC " Sparc"
  49.     #elif defined(WINCE)
  50.         #define WD_CPU_SPEC ""
  51.     #else  
  52.         #define WD_CPU_SPEC " X86"
  53.     #endif
  54. #endif
  55.  
  56. #if defined(WINNT)
  57.     #define WD_FILE_FORMAT " SYS"
  58. #elif defined(WIN95)
  59.     #define WD_FILE_FORMAT " VXD"
  60. #else
  61.     #define WD_FILE_FORMAT ""
  62. #endif
  63.  
  64. #define WD_VER_STR  WD_PROD_NAME  " V5.00 Jungo (c)2001 Build Date: " __DATE__ WD_CPU_SPEC WD_FILE_FORMAT
  65.  
  66. #if !defined(UNIX) && (defined(LINUX) || defined(SOLARIS) || defined(VXWORKS))
  67.     #define UNIX
  68. #endif
  69.  
  70. #if !defined(SPARC) && (defined(__sparc__) || defined (__sparc) || \
  71.         defined(sparc))
  72.     #define SPARC
  73. #endif
  74.  
  75. #if !defined(WIN32) && (defined(WINCE) || defined(WIN95) || defined(WINNT)) && !defined(OS2)
  76.     #define WIN32
  77. #endif
  78.  
  79. #if defined(_WIN32_WCE) && !defined(WINCE)
  80.     #define WINCE
  81. #endif
  82.  
  83. #if !defined(x86) && ( defined(LINUX) || (defined(WIN32) && !defined(WINCE) && !defined(_ALPHA_) ))
  84.     #define x86
  85. #endif
  86.  
  87. #if defined(_KERNEL) && !defined(__KERNEL__)
  88.     #define __KERNEL__
  89. #endif
  90.  
  91. #if defined( __KERNEL__) && !defined(_KERNEL)
  92.     #define _KERNEL
  93. #endif
  94.     
  95. #if !defined(WIN32) && !defined(WINCE) && !defined(UNIX) && !defined(OS2)
  96.     #define WIN32
  97. #endif
  98.  
  99. #if  !defined(POWERPC) && defined(VXWORKS) && !defined(x86)
  100.     #define POWERPC
  101. #endif
  102. #if !defined(_BIGENDIAN) && (defined (SPARC) || defined(POWERPC))
  103.     #define _BIGENDIAN
  104. #endif
  105.  
  106. #if defined(UNIX)
  107.     #if !defined(__P_TYPES__)
  108.         #if !defined(VXWORKS)
  109.             typedef void VOID;
  110.             typedef unsigned char UCHAR;
  111.             typedef unsigned short USHORT;
  112.             typedef unsigned int UINT;
  113.             typedef unsigned long ULONG;
  114.             typedef ULONG BOOL;
  115.         #endif
  116.         typedef void *PVOID;
  117.         typedef unsigned char *PBYTE;
  118.         typedef char CHAR;
  119.         typedef char *PCHAR;
  120.         typedef unsigned short *PWORD;
  121.         typedef unsigned long DWORD, *PDWORD;
  122.         typedef PVOID HANDLE;
  123.     #endif
  124.     
  125.     #if !defined(__KERNEL__)
  126.         #include <string.h>
  127.         #include <ctype.h>
  128.         #include <stdlib.h>
  129.     #endif
  130.     #define TRUE 1
  131.     #define FALSE 0
  132.     #define __cdecl
  133.     #define WINAPI
  134.     
  135.     #if defined(__KERNEL__)
  136.         #if defined(LINUX)
  137.             #include <linux/types.h>
  138.             #include <linux/string.h>
  139.         #endif
  140.     #else
  141.         #include <unistd.h> 
  142.         #if defined(LINUX)
  143.                 #include <sys/ioctl.h> /* for BSD ioctl() */
  144.             #include <unistd.h>
  145.         #else
  146.             #include <unistd.h> /* for SVR4 ioctl()*/
  147.         #endif
  148.         #if defined(VXWORKS)
  149.             #include <vxWorks.h>
  150.             #undef SPARC /* defined in vxworks.h */
  151.             #include <string.h>
  152.             #include <memLib.h>
  153.             #include <stdlib.h>
  154.             #include <taskLib.h>
  155.             #include <ioLib.h>
  156.             #include <iosLib.h>
  157.             #include <taskLib.h>
  158.             #include <semLib.h>
  159.             #include <timers.h>
  160.         #endif
  161.         #include <sys/types.h>
  162.         #include <sys/stat.h>
  163.         #include <fcntl.h>    
  164.     #endif
  165. #elif defined(OS2)
  166.     #define INCL_DOSSEMAPHORES
  167.     #define INCL_WINLOAD
  168.     #define INCL_DOSPROCESS
  169.     #define INCL_DOSDEVICES
  170.     #define __cdecl
  171.     #define WINAPI
  172.        #include <os2.h>
  173.     #include <string.h>
  174.     #include <ctype.h>    
  175.     #if !defined(__P_TYPES__)
  176.             #define __P_TYPES__
  177.         typedef unsigned short NTSTATUS;    
  178.         typedef unsigned short WORD;
  179.         typedef unsigned short *PWORD;
  180.         typedef unsigned long DWORD, *PDWORD;
  181.         typedef PVOID HANDLE;
  182.     #endif    
  183.     #define TRUE 1
  184.     #define FALSE 0
  185. #elif defined(WINCE)
  186.     #include <windows.h>
  187.     #include <winioctl.h>
  188.     typedef char CHAR;
  189. #elif defined(WIN32)
  190.     #if defined(__KERNEL__)
  191.         int sprintf(char *buffer, const char *format, ...);
  192.     #else
  193.         #include <windows.h>
  194.         #include <winioctl.h>
  195.     #endif
  196.     #if defined(__KERNEL__) && defined(WIN32)
  197.         int sprintf(char *buffer, const char *format, ...);
  198.     #endif
  199.     #if defined(__KERNEL__) && defined(WIN95) && !defined(__KERPLUG__)
  200.         #include "kdstdlib.h"
  201.     #endif
  202. #endif
  203.  
  204. static CHAR *WD_VER_MODULE = WD_VER_STR;
  205. #ifndef OS2
  206.     typedef unsigned char BYTE;
  207.     typedef unsigned short int WORD;
  208. #endif
  209.  
  210. typedef enum 
  211. {                   
  212.     CMD_NONE = 0,       // No command
  213.     CMD_END = 1,        // End command
  214.  
  215.     RP_BYTE = 10,       // Read port byte
  216.     RP_WORD = 11,       // Read port word  
  217.     RP_DWORD = 12,      // Read port dword
  218.     WP_BYTE = 13,       // Write port byte
  219.     WP_WORD = 14,       // Write port word 
  220.     WP_DWORD = 15,      // Write port dword 
  221.  
  222.     RP_SBYTE = 20,      // Read port string byte
  223.     RP_SWORD = 21,      // Read port string word  
  224.     RP_SDWORD = 22,     // Read port string dword
  225.     WP_SBYTE = 23,      // Write port string byte
  226.     WP_SWORD = 24,      // Write port string word 
  227.     WP_SDWORD = 25,     // Write port string dword 
  228.  
  229.     RM_BYTE = 30,       // Read memory byte
  230.     RM_WORD = 31,       // Read memory word  
  231.     RM_DWORD = 32,      // Read memory dword
  232.     WM_BYTE = 33,       // Write memory byte
  233.     WM_WORD = 34,       // Write memory word 
  234.     WM_DWORD = 35,      // Write memory dword 
  235.  
  236.     RM_SBYTE = 40,      // Read memory string byte
  237.     RM_SWORD = 41,      // Read memory string word  
  238.     RM_SDWORD = 42,     // Read memory string dword
  239.     WM_SBYTE = 43,      // Write memory string byte
  240.     WM_SWORD = 44,      // Write memory string word 
  241.     WM_SDWORD = 45      // Write memory string dword 
  242. } WD_TRANSFER_CMD;                                         
  243.  
  244. enum { WD_DMA_PAGES = 256 };
  245.  
  246. enum { DMA_KERNEL_BUFFER_ALLOC = 1 }; // the system allocates a contiguous buffer
  247.                                  // the user doesnt need to supply linear_address
  248. enum { DMA_KBUF_BELOW_16M = 2 }; // if DMA_KERNEL_BUFFER_ALLOC if used,
  249.                                  // this will make sure it is under 16M
  250. enum { DMA_LARGE_BUFFER   = 4 }; // if DMA_LARGE_BUFFER if used,
  251.                                  // the maximum number of pages are dwPages, and not
  252.                                  // WD_DMA_PAGES. if you lock a user buffer (not a kernel
  253.                                  // allocated buffer) that is larger than 1MB, then use this
  254.                                  // option, and allocate memory for pages.
  255.  
  256. typedef struct
  257. {
  258.     PVOID pPhysicalAddr;    // physical address of page
  259.     DWORD dwBytes;          // size of page
  260. } WD_DMA_PAGE, WD_DMA_PAGE_V30;
  261.  
  262. typedef struct 
  263. {
  264.     DWORD hDma;             // handle of dma buffer
  265.     PVOID pUserAddr;        // beginning of buffer
  266.     DWORD dwBytes;          // size of buffer
  267.     DWORD dwOptions;        // allocation options:
  268.                             // DMA_KERNEL_BUFFER_ALLOC, DMA_KBUF_BELOW_16M, DMA_LARGE_BUFFER
  269.     DWORD dwPages;          // number of pages in buffer
  270.     WD_DMA_PAGE Page[WD_DMA_PAGES];
  271. } WD_DMA, WD_DMA_V30;
  272.  
  273. typedef struct 
  274. {
  275.     DWORD cmdTrans;  // Transfer command WD_TRANSFER_CMD
  276.     DWORD dwPort;    // io port for transfer or user memory address
  277.  
  278.     // parameters used for string transfers:
  279.     DWORD dwBytes;   // for string transfer
  280.     DWORD fAutoinc;  // transfer from one port/address 
  281.                      // or use incremental range of addresses
  282.     DWORD dwOptions; // must be 0
  283.     union
  284.     {
  285.         BYTE Byte;   // use for byte transfer
  286.         WORD Word;   // use for word transfer
  287.         DWORD Dword; // use for dword transfer
  288.         PVOID pBuffer; // use for string transfer
  289.     } Data;       
  290. } WD_TRANSFER, WD_TRANSFER_V30;
  291.  
  292.  
  293. enum { INTERRUPT_LEVEL_SENSITIVE = 1 };
  294. enum { INTERRUPT_CMD_COPY = 2 };
  295. enum { INTERRUPT_CE_INT_ID = 4 };
  296.  
  297. typedef struct
  298. {
  299.     DWORD hKernelPlugIn;
  300.     DWORD dwMessage;
  301.     PVOID pData;
  302.     DWORD dwResult;
  303. } WD_KERNEL_PLUGIN_CALL, WD_KERNEL_PLUGIN_CALL_V40;
  304.  
  305. typedef struct
  306. {                                                        
  307.     DWORD hInterrupt;    // handle of interrupt
  308.     DWORD dwOptions;     // interrupt options: INTERRUPT_CMD_COPY
  309.     
  310.     WD_TRANSFER *Cmd;    // commands to do on interrupt
  311.     DWORD dwCmds;        // number of commands
  312.  
  313.     // for WD_IntEnable()
  314.     WD_KERNEL_PLUGIN_CALL kpCall; // kernel plugin call
  315.     DWORD fEnableOk;     // did WD_IntEnable() succeed
  316.  
  317.     // For WD_IntWait() and WD_IntCount()
  318.     DWORD dwCounter;     // number of interrupts received
  319.     DWORD dwLost;        // number of interrupts not yet dealt with
  320.     DWORD fStopped;      // was interrupt disabled during wait
  321. } WD_INTERRUPT, WD_INTERRUPT_V40;
  322.  
  323. typedef struct
  324. {                                                        
  325.     DWORD dwVer;  
  326.     CHAR cVer[100];
  327. } WD_VERSION, WD_VERSION_V30;
  328.  
  329. enum 
  330. {
  331.     LICENSE_DEMO = 0x1,
  332.     LICENSE_WD = 0x4, 
  333.     LICENSE_IO = 0x8,   
  334.     LICENSE_MEM = 0x10, 
  335.     LICENSE_INT = 0x20,
  336.     LICENSE_PCI    = 0x40,  
  337.     LICENSE_DMA    = 0x80, 
  338.     LICENSE_NT = 0x100,
  339.     LICENSE_95 = 0x200, 
  340.     LICENSE_ISAPNP = 0x400, 
  341.     LICENSE_PCMCIA = 0x800, 
  342.     LICENSE_PCI_DUMP = 0x1000,
  343.     LICENSE_MSG_GEN    = 0x2000, 
  344.     LICENSE_MSG_EDU = 0x4000, 
  345.     LICENSE_MSG_INT    = 0x8000,
  346.     LICENSE_KER_PLUG = 0x10000,
  347.     LICENSE_LINUX = 0x20000,    
  348.     LICENSE_CE = 0x80000,
  349.     LICENSE_VXWORKS = 0x10000000,
  350.     LICENSE_THIS_PC    = 0x100000, 
  351.     LICENSE_WIZARD = 0x200000,
  352.     LICENSE_KD = 0x400000,  
  353.     LICENSE_SOLARIS    = 0x800000,
  354.     LICENSE_CPU0 = 0x40000,     
  355.     LICENSE_CPU1 = 0x1000000,
  356.     LICENSE_CPU2 = 0x2000000,   
  357.     LICENSE_CPU3 = 0x4000000,
  358.     LICENSE_USB    = 0x8000000,    
  359.     LICENSE_OS2    = 0x20000000,
  360. };
  361.  
  362. enum
  363. {
  364.     LICENSE2_CPCI = 0x1,
  365.     LICENSE2_REMOTE = 0x2,
  366. };
  367.  
  368. enum 
  369. {
  370.     LICENSE_OS_WITH_WIZARD = LICENSE_95 | LICENSE_NT,
  371.     LICENSE_OS_WITHOUT_WIZARD = LICENSE_LINUX | LICENSE_CE | LICENSE_VXWORKS | LICENSE_SOLARIS | LICENSE_OS2,
  372. };
  373.  
  374. enum 
  375. {
  376.     LICENSE_CPU_ALL = LICENSE_CPU3 | LICENSE_CPU2 | LICENSE_CPU1 | 
  377.         LICENSE_CPU0,
  378.     LICENSE_X86 = LICENSE_CPU0,
  379.     LICENSE_ALPHA = LICENSE_CPU1,
  380.     LICENSE_SPARC = LICENSE_CPU1 | LICENSE_CPU0,
  381.     LICENSE_PPC = LICENSE_CPU2,
  382. };
  383.  
  384. typedef struct
  385. {
  386.     CHAR cLicense[100]; // buffer with license string to put
  387.                         // if empty string then get current license setting 
  388.                         // into dwLicense
  389.     DWORD dwLicense;    // returns license settings: LICENSE_DEMO, LICENSE_WD etc...
  390.     DWORD dwLicense2;    // if put license was unsuccessful (i.e. invalid license)
  391.                         // then dwLicense will return 0.
  392. } WD_LICENSE, WD_LICENSE_V44;
  393.  
  394. typedef struct 
  395. {
  396.     DWORD dwBusType;        // Bus Type: ISA, EISA, PCI, PCMCIA
  397.     DWORD dwBusNum;         // Bus number
  398.     DWORD dwSlotFunc;       // Slot number on Bus
  399. } WD_BUS, WD_BUS_V30;
  400.  
  401. enum 
  402.     WD_BUS_ISA = 1, 
  403.     WD_BUS_EISA = 2, 
  404.     WD_BUS_PCI = 5, 
  405.     WD_BUS_PCMCIA = 8,
  406. };
  407.  
  408. typedef enum 
  409.     ITEM_NONE=0, 
  410.     ITEM_INTERRUPT=1, 
  411.     ITEM_MEMORY=2, 
  412.     ITEM_IO=3, 
  413.     ITEM_BUS=5,
  414. } ITEM_TYPE;
  415.  
  416. typedef struct 
  417. {
  418.     DWORD item; // ITEM_TYPE
  419.     DWORD fNotSharable;
  420.     union
  421.     {
  422.         struct 
  423.         { // ITEM_MEMORY
  424.             DWORD dwPhysicalAddr;     // physical address on card
  425.             DWORD dwBytes;            // address range
  426.             DWORD dwTransAddr;        // returns the address to pass on to transfer commands
  427.             DWORD dwUserDirectAddr;   // returns the address for direct user read/write
  428.             DWORD dwCpuPhysicalAddr;  // returns the CPU physical address of card
  429.         } Mem;
  430.         struct
  431.         { // ITEM_IO
  432.             DWORD dwAddr;         // beginning of io address
  433.             DWORD dwBytes;        // io range
  434.         } IO;
  435.         struct
  436.         { // ITEM_INTERRUPT
  437.             DWORD dwInterrupt;    // number of interrupt to install 
  438.             DWORD dwOptions;    // interrupt options: INTERRUPT_LEVEL_SENSITIVE
  439.             DWORD hInterrupt;   // returns the handle of the interrupt installed
  440.         } Int;
  441.         WD_BUS Bus; // ITEM_BUS
  442.         struct
  443.         {
  444.             DWORD dw1;
  445.             DWORD dw2;
  446.             DWORD dw3;
  447.             DWORD dw4;
  448.             DWORD dw5;
  449.         } Val;
  450.     } I;
  451. } WD_ITEMS, WD_ITEMS_V30;
  452.  
  453. enum { WD_CARD_ITEMS = 20 };
  454.  
  455. typedef struct 
  456. {
  457.     DWORD dwItems;
  458.     WD_ITEMS Item[WD_CARD_ITEMS];
  459. } WD_CARD, WD_CARD_V30;
  460.  
  461. typedef struct
  462. {
  463.     WD_CARD Card;           // card to register
  464.     DWORD fCheckLockOnly;   // only check if card is lockable, return hCard=1 if OK
  465.     DWORD hCard;            // handle of card
  466.     DWORD dwOptions;        // should be zero
  467.     CHAR cName[32];         // name of card
  468.     CHAR cDescription[100]; // description
  469. } WD_CARD_REGISTER, WD_CARD_REGISTER_V40;
  470.  
  471. enum { WD_PCI_CARDS = 30 };
  472.  
  473. typedef struct 
  474. {
  475.     DWORD dwBus;
  476.     DWORD dwSlot;
  477.     DWORD dwFunction;
  478. } WD_PCI_SLOT;
  479.  
  480. typedef struct {
  481.     DWORD handle;
  482. } WD_HS_WATCH;
  483.  
  484. typedef struct 
  485. {
  486.     DWORD dwVendorId;
  487.     DWORD dwDeviceId;
  488. } WD_PCI_ID;
  489.  
  490. typedef struct
  491. {
  492.     WD_PCI_ID searchId;     // if dwVendorId==0 - scan all vendor IDs
  493.                             // if dwDeviceId==0 - scan all device IDs
  494.     DWORD dwCards;          // number of cards found
  495.     WD_PCI_ID cardId[WD_PCI_CARDS]; // VendorID & DeviceID of cards found
  496.     WD_PCI_SLOT cardSlot[WD_PCI_CARDS]; // pci slot info of cards found
  497. } WD_PCI_SCAN_CARDS, WD_PCI_SCAN_CARDS_V30;
  498.  
  499. typedef struct 
  500. {
  501.     WD_PCI_SLOT pciSlot;    // pci slot
  502.     WD_CARD Card;           // get card parameters for pci slot
  503. } WD_PCI_CARD_INFO, WD_PCI_CARD_INFO_V30;
  504.  
  505. typedef enum
  506.     PCI_ACCESS_OK = 0, 
  507.     PCI_ACCESS_ERROR = 1, 
  508.     PCI_BAD_BUS = 2, 
  509.     PCI_BAD_SLOT = 3,
  510. } PCI_ACCESS_RESULT;
  511.  
  512. typedef struct 
  513. {
  514.     WD_PCI_SLOT pciSlot;    // pci bus, slot and function number
  515.     PVOID       pBuffer;    // buffer for read/write
  516.     DWORD       dwOffset;   // offset in pci configuration space to read/write from
  517.     DWORD       dwBytes;    // bytes to read/write from/to buffer
  518.                             // returns the number of bytes read/wrote
  519.     DWORD       fIsRead;    // if 1 then read pci config, 0 write pci config
  520.     DWORD       dwResult;   // PCI_ACCESS_RESULT
  521. } WD_PCI_CONFIG_DUMP, WD_PCI_CONFIG_DUMP_V30;
  522.  
  523. enum { WD_ISAPNP_CARDS = 16 };
  524. enum { WD_ISAPNP_COMPATIBLE_IDS = 10 };
  525. enum { WD_ISAPNP_COMP_ID_LENGTH = 7 }; // ISA compressed ID is 7 chars long
  526. enum { WD_ISAPNP_ANSI_LENGTH = 32 }; // ISA ANSI ID is limited to 32 chars long
  527. typedef CHAR WD_ISAPNP_COMP_ID[WD_ISAPNP_COMP_ID_LENGTH+1]; 
  528. typedef CHAR WD_ISAPNP_ANSI[WD_ISAPNP_ANSI_LENGTH+1+3]; // add 3 bytes for DWORD alignment
  529. typedef struct 
  530. {
  531.     WD_ISAPNP_COMP_ID cVendor; // Vendor ID
  532.     DWORD dwSerial; // Serial number of card
  533. } WD_ISAPNP_CARD_ID;
  534.  
  535. typedef struct 
  536. {
  537.     WD_ISAPNP_CARD_ID cardId;  // VendorID & serial number of cards found
  538.     DWORD dwLogicalDevices;       // Logical devices on the card
  539.     BYTE bPnPVersionMajor;     // ISA PnP version Major
  540.     BYTE bPnPVersionMinor;     // ISA PnP version Minor
  541.     BYTE bVendorVersionMajor;  // Vendor version Major
  542.     BYTE bVendorVersionMinor;  // Vendor version Minor
  543.     WD_ISAPNP_ANSI cIdent;     // Device identifier
  544. } WD_ISAPNP_CARD, WD_ISAPNP_CARD_V40;
  545.  
  546. typedef struct 
  547. {
  548.     WD_ISAPNP_CARD_ID searchId; // if searchId.cVendor[0]==0 - scan all vendor IDs
  549.                                 // if searchId.dwSerial==0 - scan all serial numbers
  550.     DWORD dwCards;              // number of cards found
  551.     WD_ISAPNP_CARD Card[WD_ISAPNP_CARDS]; // cards found
  552. } WD_ISAPNP_SCAN_CARDS, WD_ISAPNP_SCAN_CARDS_V40;
  553.  
  554. typedef struct 
  555. {
  556.     WD_ISAPNP_CARD_ID cardId;   // VendorID and serial number of card
  557.     DWORD dwLogicalDevice;      // logical device in card
  558.     WD_ISAPNP_COMP_ID cLogicalDeviceId; // logical device ID
  559.     DWORD dwCompatibleDevices;  // number of compatible device IDs
  560.     WD_ISAPNP_COMP_ID CompatibleDevice[WD_ISAPNP_COMPATIBLE_IDS]; // Compatible device IDs
  561.     WD_ISAPNP_ANSI cIdent;      // Device identifier
  562.     WD_CARD Card;               // get card parameters for the ISA PnP card
  563. } WD_ISAPNP_CARD_INFO, WD_ISAPNP_CARD_INFO_V40;
  564.  
  565. typedef enum 
  566.     ISAPNP_ACCESS_OK = 0, 
  567.     ISAPNP_ACCESS_ERROR = 1, 
  568.     ISAPNP_BAD_ID = 2, 
  569. } ISAPNP_ACCESS_RESULT;
  570.  
  571. typedef struct 
  572. {
  573.     WD_ISAPNP_CARD_ID cardId; // VendorID and serial number of card
  574.     DWORD dwOffset;   // offset in ISA PnP configuration space to read/write from
  575.     DWORD fIsRead;    // if 1 then read ISA PnP config, 0 write ISA PnP config
  576.     BYTE  bData;      // result data of byte read/write
  577.     DWORD dwResult;   // ISAPNP_ACCESS_RESULT
  578. } WD_ISAPNP_CONFIG_DUMP, WD_ISAPNP_CONFIG_DUMP_V40;
  579.  
  580. // PCMCIA Card Services
  581.  
  582. // Extreme case - two PCMCIA slots and two multi-function (4 functions) cards
  583. enum 
  584.     WD_PCMCIA_CARDS = 8, 
  585.     WD_PCMCIA_VERSION_LEN = 4, 
  586.     WD_PCMCIA_MANUFACTURER_LEN = 48,
  587.     WD_PCMCIA_PRODUCTNAME_LEN = 48, 
  588.     WD_PCMCIA_MAX_SOCKET = 2,
  589.     WD_PCMCIA_MAX_FUNCTION = 2, 
  590. };
  591.  
  592. typedef struct 
  593. {
  594.     BYTE uSocket;      // Specifies the socket number (first socket is 0)
  595.     BYTE uFunction;    // Specifies the function number (first function is 0)
  596.     BYTE uPadding0;    // 2 bytes padding so structure will be 4 bytes aligned
  597.     BYTE uPadding1;
  598. } WD_PCMCIA_SLOT, WD_PCMCIA_SLOT_V41;
  599.  
  600. typedef struct 
  601. {
  602.     DWORD dwManufacturerId; // card manufacturer
  603.     DWORD dwCardId;         // card type and model
  604. } WD_PCMCIA_ID;
  605.  
  606. typedef struct 
  607. {
  608.     WD_PCMCIA_ID searchId;           // device ID to search for
  609.     DWORD dwCards;                   // number of cards found
  610.     WD_PCMCIA_ID cardId[WD_PCMCIA_CARDS]; // device IDs of cards found
  611.     WD_PCMCIA_SLOT cardSlot[WD_PCMCIA_CARDS]; // pcmcia slot info of cards found
  612. } WD_PCMCIA_SCAN_CARDS, WD_PCMCIA_SCAN_CARDS_V41;
  613.  
  614. typedef struct 
  615. {
  616.     WD_PCMCIA_SLOT pcmciaSlot; // pcmcia slot
  617.     WD_CARD Card;              // get card parameters for pcmcia slot
  618.     CHAR cVersion[WD_PCMCIA_VERSION_LEN];
  619.     CHAR cManufacturer[WD_PCMCIA_MANUFACTURER_LEN];
  620.     CHAR cProductName[WD_PCMCIA_PRODUCTNAME_LEN];
  621.     DWORD dwManufacturerId;    // card manufacturer
  622.     DWORD dwCardId;            // card type and model
  623.     DWORD dwFuncId;            // card function code
  624. } WD_PCMCIA_CARD_INFO, WD_PCMCIA_CARD_INFO_V41;
  625.  
  626. typedef struct 
  627. {
  628.     WD_PCMCIA_SLOT pcmciaSlot;    
  629.     PVOID pBuffer;    // buffer for read/write
  630.     DWORD dwOffset;   // offset in pcmcia configuration space to 
  631.                       //    read/write from
  632.     DWORD dwBytes;    // bytes to read/write from/to buffer
  633.                       //     returns the number of bytes read/wrote
  634.     DWORD fIsRead;    // if 1 then read pci config, 0 write pci config
  635.     DWORD dwResult;   // PCMCIA_ACCESS_RESULT
  636. } WD_PCMCIA_CONFIG_DUMP, WD_PCMCIA_CONFIG_DUMP_V41;
  637.  
  638. enum { SLEEP_NON_BUSY = 1 };
  639. typedef struct 
  640. {
  641.     DWORD dwMicroSeconds; // Sleep time in Micro Seconds (1/1,000,000 Second)
  642.     DWORD dwOptions;      // can be: SLEEP_NON_BUSY (10000 uSec +)
  643. } WD_SLEEP, WD_SLEEP_V40;
  644.  
  645. typedef enum 
  646.     D_OFF         = 0, 
  647.     D_ERROR        = 1, 
  648.     D_WARN         = 2, 
  649.     D_INFO         = 3, 
  650.     D_TRACE        = 4
  651. } DEBUG_LEVEL;
  652.  
  653. typedef enum 
  654.     S_ALL        = 0xffffffff, 
  655.     S_IO        = 0x8, 
  656.     S_MEM        = 0x10, 
  657.     S_INT        = 0x20, 
  658.     S_PCI        = 0x40,
  659.     S_DMA        = 0x80,
  660.     S_MISC        = 0x100,
  661.     S_LICENSE    = 0x200,
  662.     S_ISAPNP    = 0x400,
  663.     S_PCMCIA    = 0x800,
  664.     S_KER_PLUG    = 0x10000,
  665.     S_CARD_REG    = 0x2000,
  666.     S_KER_DRV    = 0x4000,
  667.     S_USB        = 0x8000,
  668.     S_CPCI      = 0x20000,
  669. } DEBUG_SECTION;
  670.  
  671. typedef enum 
  672.     DEBUG_STATUS = 1, 
  673.     DEBUG_SET_FILTER = 2, 
  674.     DEBUG_SET_BUFFER = 3, 
  675.     DEBUG_CLEAR_BUFFER = 4,
  676.     DEBUG_DUMP_SEC_ON = 5,
  677.     DEBUG_DUMP_SEC_OFF = 6
  678. } DEBUG_COMMAND;
  679.  
  680. typedef struct 
  681. {
  682.     DWORD dwCmd;     // DEBUG_COMMAND: DEBUG_STATUS, DEBUG_SET_FILTER, DEBUG_SET_BUFFER, DEBUG_CLEAR_BUFFER
  683.     // used for DEBUG_SET_FILTER
  684.     DWORD dwLevel;   // DEBUG_LEVEL: D_ERROR, D_WARN..., or D_OFF to turn debugging off
  685.     DWORD dwSection; // DEBUG_SECTION: for all sections in driver: S_ALL
  686.                      // for partial sections: S_IO, S_MEM...
  687.     DWORD dwLevelMessageBox; // DEBUG_LEVEL to print in a message box
  688.     // used for DEBUG_SET_BUFFER
  689.     DWORD dwBufferSize; // size of buffer in kernel
  690. } WD_DEBUG, WD_DEBUG_V40;
  691.  
  692. typedef struct 
  693. {
  694.     PCHAR pcBuffer;  // buffer to receive debug messages
  695.     DWORD dwSize;    // size of buffer in bytes
  696. } WD_DEBUG_DUMP, WD_DEBUG_DUMP_V40;
  697.  
  698. typedef struct 
  699. {
  700.     DWORD hKernelPlugIn;
  701.     PCHAR pcDriverName;
  702.     PCHAR pcDriverPath; // if NULL the driver will be searched in the windows system directory 
  703.     PVOID pOpenData;
  704. } WD_KERNEL_PLUGIN, WD_KERNEL_PLUGIN_V40;
  705.  
  706. typedef enum 
  707. {
  708.     WD_CPCI_INSERT      = 0x1,
  709.     WD_CPCI_REMOVE      = 0x2,
  710.     WD_CPCI_ACKNOWLEDGE = 0x4,
  711.     WD_CPCI_REENUM      = 0x8,
  712. } WD_CPCI_ACTION;
  713.  
  714. typedef enum
  715. {
  716.     EVENT_STATUS_OK = 0,
  717.     EVENT_STATUS_FAILED_ALLOCATE = 1,
  718. } EVENT_STATUS;
  719.  
  720. typedef struct
  721. {
  722.     DWORD dwAction; // WD_CPCI_ACTION
  723.     DWORD dwStatus; // EVENT_STATUS
  724.     WD_PCI_ID cardId;
  725.     WD_PCI_SLOT pciSlot;
  726.     DWORD dwEventId;
  727. } WD_CPCI_EVENT, WD_CPCI_EVENT_V443;
  728.  
  729. typedef struct
  730. {
  731.     WD_CPCI_EVENT cpciEvent;
  732.     DWORD hInterrupt;
  733. } WD_HS_REGISTER_EVENT, WD_HS_REGISTER_EVENT_V443;
  734.  
  735. typedef enum {
  736.     PIPE_TYPE_CONTROL     = 0,
  737.     PIPE_TYPE_ISOCHRONOUS = 1,
  738.     PIPE_TYPE_BULK        = 2,
  739.     PIPE_TYPE_INTERRUPT   = 3,
  740. } USB_PIPE_TYPE;
  741.  
  742. #define WD_USB_MAX_PIPE_NUMBER_V432 16
  743. #define WD_USB_MAX_PIPE_NUMBER 32
  744. #define WD_USB_MAX_ENDPOINTS WD_USB_MAX_PIPE_NUMBER
  745. #define WD_USB_MAX_INTERFACES 30
  746.  
  747. #define WD_USB_MAX_DEVICE_NUMBER_V432 20
  748. #define WD_USB_MAX_DEVICE_NUMBER 127
  749.  
  750. typedef struct
  751. {
  752.     DWORD dwVendorId;
  753.     DWORD dwProductId;
  754. } WD_USB_ID;
  755.  
  756. typedef enum {
  757.     USB_DIR_IN     = 1,
  758.     USB_DIR_OUT    = 2,
  759.     USB_DIR_IN_OUT = 3,
  760. } USB_DIR;
  761.  
  762. typedef struct
  763. {
  764.     DWORD dwNumber;        // Pipe 0 is the default pipe
  765.     DWORD dwMaximumPacketSize;
  766.     DWORD type;            // USB_PIPE_TYPE
  767.     DWORD direction;       // USB_DIR
  768.                            // Isochronous, Bulk, Interrupt are either USB_DIR_IN or USB_DIR_OUT
  769.                            // Control are USB_DIR_IN_OUT
  770.     DWORD dwInterval;      // interval in ms relevant to Interrupt pipes
  771. } WD_USB_PIPE_INFO, WD_USB_PIPE_INFO_V43;
  772.  
  773. typedef struct
  774. {
  775.     DWORD dwNumInterfaces;
  776.     DWORD dwValue;
  777.     DWORD dwAttributes;
  778.     DWORD MaxPower;
  779. } WD_USB_CONFIG_DESC;
  780.  
  781. typedef struct
  782. {
  783.     DWORD dwNumber;
  784.     DWORD dwAlternateSetting;
  785.     DWORD dwNumEndpoints;
  786.     DWORD dwClass;
  787.     DWORD dwSubClass;
  788.     DWORD dwProtocol;
  789.     DWORD dwIndex;
  790. } WD_USB_INTERFACE_DESC, WD_USB_INTERFACE_DESC_V43;
  791.  
  792. typedef struct
  793. {
  794.     DWORD dwEndpointAddress;
  795.     DWORD dwAttributes;
  796.     DWORD dwMaxPacketSize;
  797.     DWORD dwInterval;
  798. } WD_USB_ENDPOINT_DESC, WD_USB_ENDPOINT_DESC_V43;
  799.  
  800. typedef struct
  801. {
  802.     WD_USB_INTERFACE_DESC Interface;
  803.     WD_USB_ENDPOINT_DESC Endpoints[WD_USB_MAX_ENDPOINTS];
  804. } WD_USB_INTERFACE;
  805.  
  806. typedef struct 
  807. {
  808.     DWORD uniqueId;
  809.     DWORD dwConfigurationIndex;
  810.     WD_USB_CONFIG_DESC configuration;
  811.     DWORD dwInterfaceAlternatives;
  812.     WD_USB_INTERFACE Interface[WD_USB_MAX_INTERFACES];
  813. } WD_USB_CONFIGURATION, WD_USB_CONFIGURATION_V43;
  814.  
  815. typedef struct
  816. {
  817.     DWORD   fBusPowered;
  818.     DWORD   dwPorts;              // number of ports on this hub
  819.     DWORD   dwCharacteristics;    // Hub Charateristics
  820.     DWORD   dwPowerOnToPowerGood; // port power on till power good in 2ms
  821.     DWORD   dwHubControlCurrent;  // max current in mA
  822. } WD_USB_HUB_GENERAL_INFO, WD_USB_HUB_GENERAL_INFO_V43;
  823.  
  824. typedef struct
  825. {
  826.     WD_USB_ID deviceId;
  827.     DWORD dwHubNum;
  828.     DWORD dwPortNum;
  829.     DWORD fHub;
  830.     DWORD fFullSpeed;
  831.     DWORD dwConfigurationsNum;
  832.     DWORD deviceAddress;
  833.     WD_USB_HUB_GENERAL_INFO hubInfo;
  834. } WD_USB_DEVICE_GENERAL_INFO;
  835.  
  836. typedef struct
  837. {
  838.     DWORD dwPipes;
  839.     WD_USB_PIPE_INFO Pipe[WD_USB_MAX_PIPE_NUMBER_V432];
  840. } WD_USB_DEVICE_INFO_V432;
  841.  
  842. typedef struct
  843. {
  844.     DWORD dwPipes;
  845.     WD_USB_PIPE_INFO Pipe[WD_USB_MAX_PIPE_NUMBER];
  846. } WD_USB_DEVICE_INFO, WD_USB_DEVICE_INFO_V43;
  847.  
  848. // IOCTL Structures
  849. typedef struct 
  850. {
  851.     WD_USB_ID searchId; // if dwVendorId==0 - scan all vendor IDs
  852.                         // if dwProductId==0 - scan all product IDs
  853.     DWORD dwDevices;
  854.     DWORD uniqueId[WD_USB_MAX_DEVICE_NUMBER_V432]; // a unique id to identify the device
  855.     WD_USB_DEVICE_GENERAL_INFO deviceGeneralInfo[WD_USB_MAX_DEVICE_NUMBER_V432];
  856. } WD_USB_SCAN_DEVICES_V432;
  857.  
  858. typedef struct 
  859. {
  860.     WD_USB_ID searchId; // if dwVendorId==0 - scan all vendor IDs
  861.                         // if dwProductId==0 - scan all product IDs
  862.     DWORD dwDevices;
  863.     DWORD uniqueId[WD_USB_MAX_DEVICE_NUMBER]; // a unique id to identify the device
  864.     WD_USB_DEVICE_GENERAL_INFO deviceGeneralInfo[WD_USB_MAX_DEVICE_NUMBER];
  865. } WD_USB_SCAN_DEVICES, WD_USB_SCAN_DEVICES_V43;
  866.  
  867. // USB TRANSFER options
  868. enum { USB_TRANSFER_HALT = 1 };
  869.  
  870. typedef struct
  871. {
  872.     DWORD hDevice;      // handle of USB device to read from or write to
  873.     DWORD dwPipe;       // pipe number on device
  874.     DWORD fRead;
  875.     DWORD dwOptions;    // USB_TRANSFER options:
  876.                         //    USB_TRANSFER_HALT halts the pervious transfer
  877.     PVOID pBuffer;      // pointer to buffer to read/write
  878.     DWORD dwBytes;
  879.     DWORD dwTimeout;    // timeout for the transfer in milli-seconds. 0==>no timeout.
  880.     DWORD dwBytesTransfered;    // returns the number of bytes actually read/written
  881.     BYTE  SetupPacket[8];       // setup packet for control pipe transfer
  882.     DWORD fOK;          // transfer succeeded
  883. } WD_USB_TRANSFER, WD_USB_TRANSFER_V43;
  884.  
  885.  
  886. typedef struct {
  887.     DWORD uniqueId;                 // the device unique ID
  888.     DWORD dwConfigurationIndex;     // the index of the configuration to register
  889.     DWORD dwInterfaceNum;           // interface to register
  890.     DWORD dwInterfaceAlternate;
  891.     DWORD hDevice;                  // handle of device
  892.     WD_USB_DEVICE_INFO_V432 Device;      // description of the device
  893.     DWORD dwOptions;                // should be zero
  894.     CHAR  cName[32];                // name of card
  895.     CHAR  cDescription[100];        // description
  896. } WD_USB_DEVICE_REGISTER_V432;
  897.  
  898. typedef struct {
  899.     DWORD uniqueId;                 // the device unique ID
  900.     DWORD dwConfigurationIndex;     // the index of the configuration to register
  901.     DWORD dwInterfaceNum;           // interface to register
  902.     DWORD dwInterfaceAlternate;
  903.     DWORD hDevice;                  // handle of device
  904.     WD_USB_DEVICE_INFO Device;      // description of the device
  905.     DWORD dwOptions;                // should be zero
  906.     CHAR  cName[32];                // name of card
  907.     CHAR  cDescription[100];        // description
  908. } WD_USB_DEVICE_REGISTER, WD_USB_DEVICE_REGISTER_V43;
  909.  
  910. typedef struct
  911. {
  912.     DWORD hDevice;
  913.     DWORD dwPipe;
  914. } WD_USB_RESET_PIPE, WD_USB_RESET_PIPE_V43;
  915.  
  916. #define WD_KERNEL_DRIVER_PLUGIN_HANDLE 0xffff0000
  917.  
  918. static DWORD GlobalDW;
  919.  
  920. #ifndef BZERO
  921.     #define BZERO(buf) memset(&(buf), 0, sizeof(buf))
  922. #endif
  923.  
  924. #ifndef INVALID_HANDLE_VALUE
  925.     #define INVALID_HANDLE_VALUE ((HANDLE)(-1))
  926. #endif
  927.  
  928. #ifndef CTL_CODE
  929.     #define CTL_CODE(DeviceType, Function, Method, Access) ( \
  930.         ((DeviceType)<<16) | ((Access)<<14) | ((Function)<<2) | (Method) \
  931.     )
  932.  
  933.     #define METHOD_BUFFERED   0
  934.     #define METHOD_IN_DIRECT  1
  935.     #define METHOD_OUT_DIRECT 2
  936.     #define METHOD_NEITHER    3
  937.     #define FILE_ANY_ACCESS   0
  938.     #define FILE_READ_ACCESS  1    // file & pipe
  939.     #define FILE_WRITE_ACCESS 2    // file & pipe
  940. #endif
  941.  
  942. // Device type
  943. #define WD_TYPE 38200
  944. #define WD_CTL_CODE(wFuncNum) ((DWORD) CTL_CODE( WD_TYPE, wFuncNum, METHOD_NEITHER, FILE_ANY_ACCESS))
  945.  
  946. // WinDriver function IOCTL calls.  For details on the WinDriver functions,
  947. // see the WinDriver manual or included help files.
  948.  
  949. #define IOCTL_WD_DMA_LOCK                 WD_CTL_CODE(0x901)
  950. #define IOCTL_WD_DMA_UNLOCK               WD_CTL_CODE(0x902)
  951. #define IOCTL_WD_TRANSFER                 WD_CTL_CODE(0x903)
  952. #define IOCTL_WD_MULTI_TRANSFER           WD_CTL_CODE(0x904)
  953. #define IOCTL_WD_PCI_SCAN_CARDS           WD_CTL_CODE(0x90e)
  954. #define IOCTL_WD_PCI_GET_CARD_INFO        WD_CTL_CODE(0x90f)
  955. #define IOCTL_WD_VERSION                  WD_CTL_CODE(0x910)
  956. #define IOCTL_WD_PCI_CONFIG_DUMP          WD_CTL_CODE(0x91a)
  957. #define IOCTL_WD_KERNEL_PLUGIN_OPEN       WD_CTL_CODE(0x91b)
  958. #define IOCTL_WD_KERNEL_PLUGIN_CLOSE      WD_CTL_CODE(0x91c)
  959. #define IOCTL_WD_KERNEL_PLUGIN_CALL       WD_CTL_CODE(0x91d)
  960. #define IOCTL_WD_INT_ENABLE               WD_CTL_CODE(0x91e)
  961. #define IOCTL_WD_INT_DISABLE              WD_CTL_CODE(0x91f)
  962. #define IOCTL_WD_INT_COUNT                WD_CTL_CODE(0x920)
  963. #define IOCTL_WD_ISAPNP_SCAN_CARDS        WD_CTL_CODE(0x924)
  964. #define IOCTL_WD_ISAPNP_CONFIG_DUMP       WD_CTL_CODE(0x926)
  965. #define IOCTL_WD_SLEEP                    WD_CTL_CODE(0x927)
  966. #define IOCTL_WD_DEBUG                    WD_CTL_CODE(0x928)
  967. #define IOCTL_WD_DEBUG_DUMP               WD_CTL_CODE(0x929)
  968. #define IOCTL_WD_CARD_UNREGISTER          WD_CTL_CODE(0x92b)
  969. #define IOCTL_WD_ISAPNP_GET_CARD_INFO     WD_CTL_CODE(0x92d)
  970. #define IOCTL_WD_PCMCIA_SCAN_CARDS        WD_CTL_CODE(0x92f)
  971. #define IOCTL_WD_PCMCIA_GET_CARD_INFO     WD_CTL_CODE(0x930)
  972. #define IOCTL_WD_PCMCIA_CONFIG_DUMP       WD_CTL_CODE(0x931)
  973. #define IOCTL_WD_CARD_REGISTER            WD_CTL_CODE(0x956)
  974. #define IOCTL_WD_INT_WAIT                 WD_CTL_CODE(0x94b)
  975. #define IOCTL_WD_WATCH_PCI                WD_CTL_CODE(0x94c)
  976. #define IOCTL_WD_WATCH_PCI_START          WD_CTL_CODE(0x95f)
  977. #define IOCTL_WD_WATCH_PCI_STOP           WD_CTL_CODE(0x94e)
  978. #define IOCTL_WD_HS_EVENT_PULL            WD_CTL_CODE(0x95b)
  979. #define IOCTL_WD_HS_EVENT_SEND            WD_CTL_CODE(0x960)
  980. #define IOCTL_WD_HS_EVENT_UNREGISTER      WD_CTL_CODE(0x95d)
  981. #define IOCTL_WD_HS_EVENT_REGISTER        WD_CTL_CODE(0x95e)
  982. #define IOCTL_WD_LICENSE                  WD_CTL_CODE(0x952)
  983. #define IOCTL_WD_USB_RESET_PIPE           WD_CTL_CODE(0x93c)
  984. #define IOCTL_WD_USB_RESET_DEVICE         WD_CTL_CODE(0x93f)
  985. #define IOCTL_WD_USB_SCAN_DEVICES_V432      WD_CTL_CODE(0x940)
  986. #define IOCTL_WD_USB_SCAN_DEVICES         WD_CTL_CODE(0x95a)
  987. #define IOCTL_WD_USB_TRANSFER             WD_CTL_CODE(0x942)
  988. #define IOCTL_WD_USB_DEVICE_REGISTER      WD_CTL_CODE(0x949)
  989. #define IOCTL_WD_USB_DEVICE_UNREGISTER    WD_CTL_CODE(0x959)
  990. #define IOCTL_WD_USB_GET_CONFIGURATION    WD_CTL_CODE(0x946)
  991.  
  992. #if defined(UNIX)
  993.     typedef struct
  994.     { 
  995.         DWORD dwHeader; 
  996.         PVOID pData; 
  997.         DWORD dwSize;
  998.     } WD_IOCTL_HEADER;
  999.     
  1000.     enum { WD_IOCTL_HEADER_CODE = 0xa410b413 };
  1001. #endif
  1002.  
  1003. #if defined(__KERNEL__) || defined(OS2)
  1004.     #if defined(OS2)
  1005.         DWORD EXPENTRY wdr_open();
  1006.         NTSTATUS EXPENTRY wdr_close(HANDLE h);
  1007.         NTSTATUS EXPENTRY wdr_ioctl(HANDLE h, DWORD dwFuncNum, PVOID pParam, DWORD dwSize);
  1008.         #define WD_Open() ((HANDLE)wdr_open()) 
  1009.  
  1010.         #define WD_Close(h) wdr_close(h)
  1011.         #define WD_FUNCTION(wFuncNum, h, pParam, dwSize, fWait) \
  1012.         { \
  1013.             wdr_ioctl(h, \
  1014.                 wFuncNum, \
  1015.                  pParam, \
  1016.                  dwSize \
  1017.                 ); \
  1018.         }
  1019.     #else
  1020.         HANDLE __cdecl WD_Open();
  1021.         void __cdecl WD_Close(HANDLE hWD);
  1022.         ULONG __cdecl KP_DeviceIoControl(DWORD dwFuncNum, HANDLE h, PVOID pParam,
  1023.             DWORD dwSize);
  1024.         #define WD_FUNCTION(wFuncNum, h, pParam, dwSize, fWait) \
  1025.             KP_DeviceIoControl(\
  1026.                 (DWORD) wFuncNum, h,\
  1027.                 (PVOID) pParam, (DWORD) dwSize\
  1028.                 ) 
  1029.     #endif
  1030. #else
  1031.     #if defined(UNIX)
  1032.         static inline ULONG WD_FUNCTION_LOCAL( DWORD wFuncNum, HANDLE h,
  1033.                 PVOID pParam, DWORD dwSize, BOOL fWait)
  1034.         {
  1035.             WD_IOCTL_HEADER ioctl_hdr;
  1036.             ioctl_hdr.dwHeader = WD_IOCTL_HEADER_CODE;
  1037.             ioctl_hdr.pData = pParam;
  1038.             ioctl_hdr.dwSize = dwSize;
  1039.             #if defined(VXWORKS)
  1040.                 return (ULONG) ioctl((int)(h), wFuncNum, (int)&ioctl_hdr);
  1041.             #elif defined(LINUX) || defined(SOLARIS)
  1042.                 return (ULONG) ioctl((int)(h), wFuncNum, &ioctl_hdr);
  1043.             #endif
  1044.         }
  1045.  
  1046.         #if defined(VXWORKS)
  1047.             #define WD_OpenLocal()\
  1048.                 ((HANDLE)open("/windrvr", O_RDWR, 0644))
  1049.         #else
  1050.             #define WD_OpenLocal()\
  1051.                 ((HANDLE)open("/dev/windrvr", O_RDWR))
  1052.         #endif
  1053.             
  1054.         #define WD_CloseLocal(h)\
  1055.             close((int) (h))
  1056.     
  1057.     #elif defined(WINCE) && defined(_WIN32_WCE_EMULATION)
  1058.         HANDLE WINAPI WCE_EMU_WD_Open();
  1059.         void WINAPI WCE_EMU_WD_Close(HANDLE hWD);
  1060.         BOOL WINAPI WCE_EMU_WD_FUNCTION(DWORD wFuncNum, HANDLE h, PVOID 
  1061.             pParam, DWORD dwSize);
  1062.         #define WD_OpenLocal() WCE_EMU_WD_Open()
  1063.         #define WD_CloseLocal(h) WCE_EMU_WD_Close(h)
  1064.         #define WD_FUNCTION_LOCAL(wFuncNum, h, pParam, dwSize, fWait) \
  1065.             WCE_EMU_WD_FUNCTION(wFuncNum, h, pParam, dwSize)
  1066.     #elif defined(WIN32) || defined(WINCE)
  1067.         #define WD_CloseLocal(h)\
  1068.             CloseHandle(h)
  1069.         #if defined(WINCE)
  1070.             void WINAPI SetProcPermissions(DWORD dwPermissions);
  1071.             #define WD_OpenLocal()\
  1072.                 (SetProcPermissions(0xFFFF), CreateFile(\
  1073.                     TEXT("WDR1:"),\
  1074.                     GENERIC_READ,\
  1075.                     FILE_SHARE_READ | FILE_SHARE_WRITE,\
  1076.                     NULL, OPEN_EXISTING, 0, NULL))
  1077.             #define WD_FUNCTION_LOCAL(wFuncNum, h, pParam, dwSize, fWait)\
  1078.                 ((DWORD) DeviceIoControl(h, wFuncNum, pParam, dwSize, NULL, 0,\
  1079.                     &GlobalDW, NULL))
  1080.         #elif defined(WIN32)
  1081.             #define WD_OpenLocal()\
  1082.                 CreateFile(\
  1083.                     TEXT("\\\\.\\WINDRVR"),\
  1084.                     GENERIC_READ,\
  1085.                     FILE_SHARE_READ | FILE_SHARE_WRITE,\
  1086.                     NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL)  
  1087.             static DWORD WD_FUNCTION_LOCAL(DWORD wFuncNum, HANDLE h,
  1088.                 PVOID pParam, DWORD dwSize, BOOL fWait)
  1089.             {
  1090.                 HANDLE hWD = fWait ? WD_OpenLocal() : h;
  1091.                 DWORD rc;
  1092.                 if (hWD==INVALID_HANDLE_VALUE)
  1093.                     return (DWORD) -1;
  1094.                 rc = (DWORD) DeviceIoControl(hWD, (DWORD) wFuncNum, (PVOID) pParam,
  1095.                     (DWORD) dwSize, NULL, 0, &GlobalDW, NULL);
  1096.                 if (fWait)
  1097.                     WD_CloseLocal(hWD);
  1098.                 return rc;
  1099.             }
  1100.         #endif
  1101.     #endif
  1102.     #ifndef _WINDRVR_NET_H_ 
  1103.         #define WD_FUNCTION WD_FUNCTION_LOCAL
  1104.         #define WD_Close WD_CloseLocal
  1105.         #define WD_Open WD_OpenLocal
  1106.     #endif
  1107. #endif
  1108.  
  1109. #define WD_Debug(h,pDebug)\
  1110.     WD_FUNCTION(IOCTL_WD_DEBUG, h, pDebug, sizeof (WD_DEBUG), FALSE)
  1111. #define WD_DebugDump(h,pDebugDump)\
  1112.     WD_FUNCTION(IOCTL_WD_DEBUG_DUMP, h, pDebugDump, sizeof (WD_DEBUG_DUMP), FALSE)
  1113. #define WD_Transfer(h,pTransfer)\
  1114.     WD_FUNCTION(IOCTL_WD_TRANSFER, h, pTransfer, sizeof (WD_TRANSFER), FALSE)
  1115. #define WD_MultiTransfer(h,pTransferArray,dwNumTransfers)\
  1116.     WD_FUNCTION(IOCTL_WD_MULTI_TRANSFER, h, pTransferArray, sizeof (WD_TRANSFER) * dwNumTransfers, FALSE)
  1117. #define WD_DMALock(h,pDma)\
  1118.     WD_FUNCTION(IOCTL_WD_DMA_LOCK, h, pDma, sizeof (WD_DMA), FALSE)
  1119. #define WD_DMAUnlock(h,pDma)\
  1120.     WD_FUNCTION(IOCTL_WD_DMA_UNLOCK, h, pDma, sizeof (WD_DMA), FALSE)
  1121. #define WD_CardRegister(h,pCard)\
  1122.     WD_FUNCTION(IOCTL_WD_CARD_REGISTER, h, pCard, sizeof (WD_CARD_REGISTER), FALSE)
  1123. #define WD_CardUnregister(h,pCard)\
  1124.     WD_FUNCTION(IOCTL_WD_CARD_UNREGISTER, h, pCard, sizeof (WD_CARD_REGISTER), FALSE)
  1125. #define WD_PciScanCards(h,pPciScan)\
  1126.     WD_FUNCTION(IOCTL_WD_PCI_SCAN_CARDS, h, pPciScan, sizeof (WD_PCI_SCAN_CARDS), FALSE)
  1127. #define WD_PciGetCardInfo(h,pPciCard)\
  1128.     WD_FUNCTION(IOCTL_WD_PCI_GET_CARD_INFO, h, pPciCard, sizeof (WD_PCI_CARD_INFO), FALSE)
  1129. #define WD_PciConfigDump(h,pPciConfigDump)\
  1130.     WD_FUNCTION(IOCTL_WD_PCI_CONFIG_DUMP, h, pPciConfigDump, sizeof (WD_PCI_CONFIG_DUMP), FALSE)
  1131. #define WD_Version(h,pVerInfo)\
  1132.     WD_FUNCTION(IOCTL_WD_VERSION, h, pVerInfo, sizeof (WD_VERSION), FALSE)
  1133. #define WD_License(h,pLicense)\
  1134.     WD_FUNCTION(IOCTL_WD_LICENSE, h, pLicense, sizeof (WD_LICENSE), FALSE)
  1135. #define WD_KernelPlugInOpen(h,pKernelPlugIn)\
  1136.     WD_FUNCTION(IOCTL_WD_KERNEL_PLUGIN_OPEN, h, pKernelPlugIn, sizeof (WD_KERNEL_PLUGIN), FALSE)
  1137. #define WD_KernelPlugInClose(h,pKernelPlugIn)\
  1138.     WD_FUNCTION(IOCTL_WD_KERNEL_PLUGIN_CLOSE, h, pKernelPlugIn, sizeof (WD_KERNEL_PLUGIN), FALSE)
  1139. #define WD_KernelPlugInCall(h,pKernelPlugInCall)\
  1140.     WD_FUNCTION(IOCTL_WD_KERNEL_PLUGIN_CALL, h, pKernelPlugInCall, sizeof (WD_KERNEL_PLUGIN_CALL), FALSE)
  1141. #define WD_IntEnable(h,pInterrupt)\
  1142.     WD_FUNCTION(IOCTL_WD_INT_ENABLE, h, pInterrupt, sizeof (WD_INTERRUPT), FALSE)
  1143. #define WD_IntDisable(h,pInterrupt)\
  1144.     WD_FUNCTION(IOCTL_WD_INT_DISABLE, h, pInterrupt, sizeof (WD_INTERRUPT), FALSE)
  1145. #define WD_IntCount(h,pInterrupt)\
  1146.     WD_FUNCTION(IOCTL_WD_INT_COUNT, h, pInterrupt, sizeof (WD_INTERRUPT), FALSE)
  1147. #define WD_IntWait(h,pInterrupt)\
  1148.     WD_FUNCTION(IOCTL_WD_INT_WAIT, h, pInterrupt, sizeof (WD_INTERRUPT), TRUE)
  1149. #define WD_IsapnpScanCards(h,pIsapnpScan)\
  1150.     WD_FUNCTION(IOCTL_WD_ISAPNP_SCAN_CARDS, h, pIsapnpScan, sizeof (WD_ISAPNP_SCAN_CARDS), FALSE)
  1151. #define WD_IsapnpGetCardInfo(h,pIsapnpCard)\
  1152.     WD_FUNCTION(IOCTL_WD_ISAPNP_GET_CARD_INFO, h, pIsapnpCard, sizeof (WD_ISAPNP_CARD_INFO), FALSE)
  1153. #define WD_IsapnpConfigDump(h,pIsapnpConfigDump)\
  1154.     WD_FUNCTION(IOCTL_WD_ISAPNP_CONFIG_DUMP, h, pIsapnpConfigDump, sizeof (WD_ISAPNP_CONFIG_DUMP), FALSE)
  1155. #define WD_PcmciaScanCards(h,pPcmciaScan)\
  1156.     WD_FUNCTION(IOCTL_WD_PCMCIA_SCAN_CARDS, h, pPcmciaScan, sizeof (WD_PCMCIA_SCAN_CARDS), FALSE)
  1157. #define WD_PcmciaGetCardInfo(h,pPcmciaCard)\
  1158.     WD_FUNCTION(IOCTL_WD_PCMCIA_GET_CARD_INFO, h, pPcmciaCard, sizeof (WD_PCMCIA_CARD_INFO), FALSE)
  1159. #define WD_PcmciaConfigDump(h,pPcmciaConfigDump)\
  1160.     WD_FUNCTION(IOCTL_WD_PCMCIA_CONFIG_DUMP, h, pPcmciaConfigDump, sizeof (WD_PCMCIA_CONFIG_DUMP), FALSE)
  1161. #define WD_Sleep(h,pSleep)\
  1162.     WD_FUNCTION(IOCTL_WD_SLEEP, h, pSleep, sizeof (WD_SLEEP), FALSE)
  1163. #define WD_WatchPciStart(h, pHsWatch)\
  1164.     WD_FUNCTION(IOCTL_WD_WATCH_PCI_START, h, pHsWatch, sizeof(WD_HS_WATCH), FALSE)
  1165. #define WD_WatchPciStop(h, pHsWatch)\
  1166.     WD_FUNCTION(IOCTL_WD_WATCH_PCI_STOP, h, pHsWatch, sizeof(WD_HS_WATCH), FALSE)
  1167. #define WD_HsEventPull(h, pHsEvent)\
  1168.     WD_FUNCTION(IOCTL_WD_HS_EVENT_PULL, h, pHsEvent, sizeof (WD_HS_REGISTER_EVENT), FALSE)
  1169. #define WD_HsEventSend(h, pHsEvent)\
  1170.     WD_FUNCTION(IOCTL_WD_HS_EVENT_SEND, h, pHsEvent, sizeof (WD_HS_REGISTER_EVENT), FALSE)
  1171. #define WD_HsEventUnregister(h, pHsEvent)\
  1172.     WD_FUNCTION(IOCTL_WD_HS_EVENT_UNREGISTER, h, pHsEvent, sizeof (WD_HS_REGISTER_EVENT), FALSE)
  1173. #define WD_HsEventRegister(h, pHsEvent)\
  1174.     WD_FUNCTION(IOCTL_WD_HS_EVENT_REGISTER, h, pHsEvent, sizeof (WD_HS_REGISTER_EVENT), FALSE)
  1175. #define WD_UsbScanDevice(h, pScan)\
  1176.     WD_FUNCTION(IOCTL_WD_USB_SCAN_DEVICES, h, pScan,sizeof(WD_USB_SCAN_DEVICES), FALSE)
  1177. #define WD_UsbScanDeviceV432(h, pScan)\
  1178.     WD_FUNCTION(IOCTL_WD_USB_SCAN_DEVICES_V432, h, pScan,sizeof(WD_USB_SCAN_DEVICES_V432), FALSE)
  1179. #define WD_UsbGetConfiguration(h, pConfig) \
  1180.     WD_FUNCTION(IOCTL_WD_USB_GET_CONFIGURATION, h, pConfig, sizeof(WD_USB_CONFIGURATION), FALSE)
  1181. #define WD_UsbDeviceRegister(h, pRegister)\
  1182.     WD_FUNCTION(IOCTL_WD_USB_DEVICE_REGISTER, h, pRegister, sizeof(WD_USB_DEVICE_REGISTER), FALSE)
  1183. #define WD_UsbTransfer(h, pTrans)\
  1184.     WD_FUNCTION(IOCTL_WD_USB_TRANSFER, h, pTrans, sizeof(WD_USB_TRANSFER), TRUE)
  1185. #define WD_UsbDeviceUnregister(h, pRegister)\
  1186.     WD_FUNCTION(IOCTL_WD_USB_DEVICE_UNREGISTER, h, pRegister, sizeof(WD_USB_DEVICE_REGISTER), FALSE)
  1187. #define WD_UsbResetPipe(h, pResetPipe)\
  1188.     WD_FUNCTION(IOCTL_WD_USB_RESET_PIPE, h, pResetPipe, sizeof(WD_USB_RESET_PIPE), FALSE)
  1189. #define WD_UsbResetDevice(h, hDevice)\
  1190.     WD_FUNCTION(IOCTL_WD_USB_RESET_DEVICE, h, &hDevice, sizeof(DWORD), FALSE)
  1191.  
  1192. #ifdef __cplusplus
  1193. }
  1194. #endif
  1195.  
  1196. #endif
  1197.  
  1198.